package com.sfac.hqyj.springBoot.modules.test.repository;

import com.sfac.hqyj.springBoot.modules.test.entity.Student;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface StudentRepository extends JpaRepository<Student, Integer>,
        JpaSpecificationExecutor<Student> {

    Student findByStudentName(String studentName);

    //    @Query(nativeQuery = true, value = "select * from test_student where id = :id")
    @Query(value = "from Student where id = :id")
    Student getStudentById(@Param("id") int id);

    @Modifying
    @Query(nativeQuery = true, value = "update test_student " +
            "set student_name = :#{#student.studentName} where id = :#{#student.id}")
    void updateStudent(@Param("student") Student student);
}
